package com.lwm.tx.program.service.impl;

import com.lwm.jdbc.pojo.AccountDO;
import com.lwm.tx.program.dao.IAccountDAO;
import com.lwm.tx.program.service.IAccountService;

/**
 * @author liweimin
 * @date 2021/6/12 20:46
 * @since
 */
public class AccountServiceImpl implements IAccountService {

    private IAccountDAO accountDAO;

    public void setAccountDAO(IAccountDAO accountDAO) {
        this.accountDAO = accountDAO;
    }

    @Override
    public AccountDO findAccountById(Integer id) {
        return accountDAO.selectAccountById(id);
    }

    @Override
    public void transfer(String sourceName, String targetName, Float money) {
        AccountDO account = accountDAO.selectAccountByName(sourceName);
        AccountDO account1 = accountDAO.selectAccountByName(targetName);

        account.setMoney(account.getMoney() - money);
        account1.setMoney(account1.getMoney() + money);

        accountDAO.updateAccount(account);
        int i = 1 / 0;
        accountDAO.updateAccount(account1);
    }
}
